//
//  KBVisitor.swift
//  VVeibo110
//
//  Created by kongbin on 16/8/9.
//  Copyright © 2016年 kongbin. All rights reserved.
//

import UIKit
import SnapKit

class KBVisitor: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   
    //供外界访问的方法
    func setupVisitorInfo(imageName: String? , title: String?){
        
        if let img = imageName, let tit = title {
            
            iconImageView.image = UIImage(named: img )
            
            messageLabel.text = tit
            //隐藏圈圈
            clImage.hidden = true
            
        }else{
        //代表首页
        setAnmite()
        }
    }
    
    
    
    
    
    //设置圆圈动画
    func setAnmite(){
        let anmi = CABasicAnimation(keyPath:"transform.rotation")
        //旋转多少度
        anmi.toValue = M_PI * 2
        //设置动画时长
        anmi.duration = 10
        
        //设置循环次数
        anmi.repeatCount = MAXFLOAT
        
        //取消退出自动移除动画
        anmi.removedOnCompletion = false
        //添加动画
        clImage.layer.addAnimation(anmi, forKey: nil)
        
    }
    
    
    
    
    //设置约束
    private func setupUI (){
        
        backgroundColor = RGB(237, green: 237, blue: 237, alpha: 1)
        
        //添加控件
        
        addSubview(clImage)
        addSubview(makeImage)
        addSubview(messageLabel)
        addSubview(registerBtn)
        addSubview(loginBtn)
        addSubview(iconImageView)

//        01
        clImage.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
            
        }
        
//        02
        makeImage.snp_makeConstraints { (make) in
            make.center.equalTo(self)
            
        }
//        03
        iconImageView.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
            
        }
        
//
//        04
        messageLabel.snp_makeConstraints { (make) in
        
            make.top.equalTo(makeImage.snp_bottom).offset(16)
            
            make.height.equalTo(36)
            make.centerX.equalTo(self)
        }

//        05
        registerBtn.snp_makeConstraints { (make) in
            
            make.leading.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSize(width: 100, height: 36))
            
            
        }
//
        loginBtn.snp_makeConstraints { (make) in
            
            make.size.top.equalTo(registerBtn)
            make.trailing.equalTo(messageLabel)
            
            
        }
        
    }
    
    
    //懒加载控件
    //圆圈
    private lazy var clImage :UIImageView = UIImageView.init(imageName: "visitordiscover_feed_image_smallicon")
    //遮挡
    private lazy var makeImage: UIImageView = UIImageView.init(imageName: "visitordiscover_feed_mask_smallicon")
    
    //房子
    private lazy var iconImageView :UIImageView = UIImageView.init(imageName: "visitordiscover_feed_image_house")
    
    //文字
    private lazy var messageLabel :UILabel =  {
    
        let lab :UILabel = UILabel()
        lab.textColor = appColor
        lab.font = UIFont.systemFontOfSize(15)
        lab.numberOfLines = 0
        lab.textAlignment = .Center
    lab.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        lab.preferredMaxLayoutWidth = 240
        
    return lab
    
    }()
    

    
    //懒加载按钮
    //注册按钮
    private lazy var registerBtn :UIButton = {
    
        let rbtn :UIButton = UIButton()
        
        rbtn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        rbtn.setTitle("注册", forState: UIControlState.Normal)
        rbtn.setTitleColor(appColor, forState: UIControlState.Normal)
      rbtn.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        return rbtn
    }()
    
    //登录按钮
    private lazy var loginBtn :UIButton = {
    
        let lbtn :UIButton = UIButton()
        
        lbtn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        lbtn.setTitle("登录", forState: UIControlState.Normal)
        lbtn.setTitleColor(appColor, forState: UIControlState.Normal)
        lbtn.titleLabel?.font = UIFont.systemFontOfSize(15)
    
    
    return lbtn
    }()
    
    

}
